[BITS 32]
;显示字符串的函数
; DisplayStr (string* s,color c,uint x,uint y)
DisplayStr:
    push esi
    push edi
    push eax

    mov esi, [esp+0x10] ; 字符串首地址
    mov eax, [esp+0x14] ; x,y位置，颜色
    mov ecx, eax
    shr ecx, 0x10       ;颜色
    mov edi, eax
    and edi, 0xff
    shr eax, 0x8
    and eax, 0xff
    mov ebx, 80
    mul ebx 
    add edi, eax
    shl edi,1
    xor eax, eax
    mov ah, cl
    start:
        lodsb 
        test al, al
        jz end
        mov [gs:edi], ax
        add edi, 2
        jmp start ; 继续显示下一个
    end:          ; 显示完毕
        pop eax
        pop edi
        pop esi
        ret

LABLE_BUFFER:
    times 32 db 0 

; 显示内存信息
; DisplayMem(int byte)
DisPlayByte:
    push eax
    mov ecx, 0x2
.start:
    shr eax, 0x4
    and eax, 0xf
    cmp al, 0xa
    jl .1
    sub al, 0xa
    add al, 'a'
    jmp .2
.1:
    add al, '0'
.2:
    mov ah, 0x0f
    mov [gs:edi],ax
    add edi, 2
    mov eax, [esp]
    shl eax, 0x4
    loop .start
.end:
    pop eax
    ret
    
; DisplayReg

DisplayReg:
    push eax
    push ecx
    push ebx
    push dword 4    ;局部变量
    mov bl, 24
.1:
    mov cl, bl
    shr eax, cl
    and eax, 0xff
    call DisPlayByte
    sub bl, 8
    mov eax, [esp+12]
    sub dword [esp], 1
    cmp dword [esp], 0
    jnz .1
    add esp, 4
    pop ebx
    pop ecx
    pop eax
    ret

DislpayReturn:
    push eax
    push ebx

    mov eax, edi
    mov bl, 160
    div bl
    and eax, 0xff
    inc eax
    mov bl, 160
    mul bl
    mov edi, eax

    pop ebx
    pop eax
    ret

; 内存复制函数：
; memcpy(void* dest, void* src, size_t sz)
memcpy:
    push esi
    push edi
    push ecx

    mov eax, [esp+24]
    mov esi, [esp+20]
    mov edi, [esp+16]
    xor edx , edx
    mov ebx, 4      ;打算一次4字节移动
    div ebx
    mov ecx, eax    ;结果，即有多少个双字
    test ecx, ecx
    jz .3
.1:
    lodsd 
    stosd
    loop .1
    mov ecx, edx    ;余数
    test ecx, ecx
    jz .3
.2:
    lodsb 
    stosb
    loop .2 
.3:
    pop ecx
    pop edi
    pop esi

    ret